import Taro, { Component } from '@tarojs/taro'
import { View, Image } from '@tarojs/components'
import './index.styl'

interface Star {
  props: {
    readonly num: number,
    readonly type: number // 酒店性及类型：是否官方评级(1是 显示星级 2不是 显示钻级)
  }
}
interface PageState {
  readonly imgStarUrl: string,
  readonly imgJewelUrl: string,
  starList: any[]
}
class Star extends Component {
  constructor() {
    super(...arguments)
  }
  state: PageState = {
    imgStarUrl: 'https://image.yktour.com.cn/g1/M00/07/15/CgAMDFzsmdqAGf9NAAACkQLEi-M715.png',
    imgJewelUrl: 'https://image.yktour.com.cn/g1/M00/07/1B/CgAMDFzxjgWALv9vAAADHao9X5k063.png',
    starList: []
  }
  componentWillMount() {
    let setStarList: any[] = []
    for(let i = 0; i < this.props.num; i ++) {
      setStarList.push('')
    }
    this.setState({ starList: setStarList })
  }
  render() {
    return (
      <View className='stars'>
        {
          this.state.starList.map((item, index) => (
            <Image
              className='icon'
              mode='widthFix'
              key={index}
              src={this.props.type === 1 ? this.state.imgStarUrl : this.state.imgJewelUrl}></Image>
          ))
        }
      </View>
    )
  }
}
export default Star